package com.tgy.myplus.service.impl;

import com.tgy.myplus.entity.Student;
import com.tgy.myplus.dao.StudentDao;
import com.tgy.myplus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Student)表服务实现类
 *
 * @author makejava
 * @since 2021-10-11 20:36:15
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;

    /**
     *
     * @return 学生实体列表
     */
    @Override
    public List<Student> querryAll() {
        List list = studentDao.selectList(null);
        list.forEach(System.out::println);
        return list;
    }
    @Override
    public int insert(Student student) {
        return studentDao.insert(student);
    }

    public int delete(Student student){
        return studentDao.deleteById(student);
    }

    public int update(Student student){
        return studentDao.updateById(student);
    }

    public List<Student> queryByEntity(Student student){
        Map<String, Object> mapIn = new HashMap<>();
        mapIn.put("id",student.getId());
        mapIn.put("age",student.getAge());
        if(student.getSex() != null)
        {
            mapIn.put("sex",student.getSex());
        }
        mapIn.put("name",student.getName());
        if(student.getHobby()!=null){
            mapIn.put("hobby",student.getHobby());
        }
        return studentDao.selectByMap(mapIn);
    }

}
